	<?php
	session_start();
	if(!session_is_registered(myusername)){
	//header("location:index.html");
	$name = $_SESSION['name'];
	$rusername = $_SESSION['username'];
	
	}
	?>			
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
				<html>
				<head>
				</head>
				<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
				<title>Images already diagnosed</title>
			
				<!--creates cookie called 'imagePath' to store location of image. expires at end of session
				<script>
				function setCookie(urlParam){
				var url= urlParam.toString();
				var query_string = url.split("?");
				var param_item = query_string[1].split("=");
				
				
				document.cookie = 'imagePath='+param_item[1]+';'
				}
				
				</script>-->
				
				<body>
<?php
	include "config.php";
	$image_query = "SELECT DISTINCT image_id FROM annotations";
	$image_result = mysql_query($image_query);
	//echo "<h3>There are ". mysql_num_rows($image_result) ." images with diagnoses to be rated.</h3>";
	

	while($image_row = mysql_fetch_array($image_result))
	{	
		
		$img_file_query = "SELECT * FROM images WHERE id =".$image_row[image_id];
		$img_file_result = mysql_query($img_file_query);
		$img_file_row = mysql_fetch_array($img_file_result);
		$annotation_query = "SELECT * FROM annotations,users WHERE annotations.user_id = users.id AND annotations.image_id =".$image_row[image_id];
		$annotation_result = mysql_query($annotation_query);
		//echo "<div class=\"annotation_table\">";
		$votes_query = "SELECT * FROM annotations WHERE (votes_up - votes_down >= 50) AND image_id =".$image_row[image_id];
		$votes_results = mysql_query($votes_query);
		if (mysql_num_rows($votes_results) == 0)
		{
		echo "<table border=\"1\">";
		echo "<tr><th>Image</th><th>Annotator</th><th>Votes Up</th><th>Votes Down</th></tr>";
		echo "<tr><td rowspan=\"" . mysql_num_rows($annotation_result) . "\">";
		echo "<a href = \"view_image.php?path=" . $img_file_row[file_path]. "\">";
		echo "<img src = \"" . $img_file_row[file_path] . "\" width=\"240\"/>";
		echo "</a></td>";
		
		
		while($annotation_row = mysql_fetch_array($annotation_result))
		{	
			echo "<td>";
			echo $annotation_row[username] ."</td><td>" . $annotation_row[votes_up] . "</td><td>" . $annotation_row[votes_down] . "</td>";
			echo "</td></tr><tr>";
		}
		echo "</tr>";
		echo "</table>";
		}

		//echo "</div>";
	}
				
		
		if (mysql_num_rows($image_result) == 0) {
		echo "<h3>No images to be diagnosed. Click <a href='welcome.php'>here</a> to go back</h3>";
		}
		mysql_close($con);
		?>
</body>
</html>
	
